home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / PCTAGS15.ARJ / CTAG.E < prev    next >
Text File  |  1991-10-07  |  74KB  |  2,162 lines

  1. /*
  2.  EPSHeader
  3.  
  4.    File: ctag.c
  5.    Author: J. Kercheval
  6.    Created: Sun, 07/14/1991  17:24:44
  7. */
  8. /*
  9.  EPSRevision History
  10.  
  11.    J. Kercheval  Sat, 07/27/1991  22:08:04  creation
  12.    J. Kercheval  Sun, 08/18/1991  20:58:13  completion of C_get_token()
  13.    J. Kercheval  Wed, 08/21/1991  22:34:49  place function recognition
  14.    J. Kercheval  Wed, 08/21/1991  23:11:17  add defines and macros
  15.    J. Kercheval  Wed, 08/21/1991  23:54:33  add typedef and class parsing
  16.    J. Kercheval  Thu, 08/22/1991  23:53:51  add global variables
  17.    J. Kercheval  Thu, 08/22/1991  23:54:05  add enum, struct, union
  18.    J. Kercheval  Thu, 08/22/1991  23:54:28  add globals via typedefs
  19.    J. Kercheval  Sun, 08/25/1991  23:09:28  complete semantic parser
  20.    J. Kercheval  Tue, 08/27/1991  23:28:34  fix bug in typedef, struct, enum and union declarations
  21.    J. Kercheval  Sat, 08/31/1991  23:58:03  add prototype parsing
  22.    J. Kercheval  Tue, 09/03/1991  22:28:55  move many macros to functions
  23.    J. Kercheval  Tue, 09/03/1991  23:05:34  clean code and consolidate to functions
  24.    J. Kercheval  Sun, 09/08/1991  13:24:53  minor bug fix in function and global variable parser
  25.    J. Kercheval  Sun, 09/08/1991  21:31:06  fix bug in lexical parser
  26.    J. Kercheval  Sun, 09/08/1991  23:44:46  \v is not a valid literal in Epsilon, remove it
  27.    J. Kercheval  Mon, 09/09/1991  21:49:00  fix bug in function parser
  28.    J. Kercheval  Mon, 09/09/1991  22:44:46  fix bug in define parser
  29.    J. Kercheval  Tue, 09/10/1991  22:06:09  fix typedef parser
  30.    J. Kercheval  Wed, 09/11/1991  02:04:48  add extern symbol recognition
  31.    J. Kercheval  Wed, 09/11/1991  19:49:11  fix bug in function pointer variable declaration
  32.    J. Kercheval  Wed, 09/11/1991  20:38:13  add support for function pointer variable declarations after first declaration
  33.    J. Kercheval  Wed, 09/11/1991  21:51:37  move #directive parsing between semantic and lexical parser
  34.    J. Kercheval  Thu, 09/12/1991  22:44:43  add support for #ifdef blocks to avoid unmatched parens in ToLevelZero parsing
  35.    J. Kercheval  Fri, 09/13/1991  01:17:05  add when_loading() to remap def_srch_case_map[]
  36.    J. Kercheval  Wed, 09/18/1991  22:05:02  fix bug in GetToken and DiscardLine
  37.    J. Kercheval  Thu, 09/19/1991  22:26:09  fix bug in lexical parser when parsing non C syntax files
  38.    J. Kercheval  Thu, 10/03/1991  12:47:53  add .cc and .cpp extensions
  39.    J. Kercheval  Thu, 10/03/1991  18:15:10  add support for Static declarations
  40.    J. Kercheval  Fri, 10/04/1991  11:13:23  add support for tagging enumeration constants
  41.    J. Kercheval  Mon, 10/07/1991  09:36:07  create CParseEnumerationConstants()
  42. */
  43.  
  44. /*
  45.  * This file implements tagging for .C, .H and .E files which contain
  46.  * standard C and C++ syntax.  This file defines no new commands and is
  47.  * intended to work with the tags package included with V5.0 of Epsilon.
  48.  * There is no problem using modified tags packages providing calls are made
  49.  * to tags_suffix_???() routines in the same way Epsilon does this and that
  50.  * an output routine add_tag() is used.  All that should be required is to
  51.  * compile and load this file and this module will be used transparently to
  52.  * you.  If you wish to costumize the types of tags output modify the global
  53.  * variables CTagWant?????? which when TRUE allow the output of that type of
  54.  * tag and when FALSE prohibit that type of tag.
  55.  *
  56.  * This module implements tagging for union, struct, enum, typedef, #define,
  57.  * global variables, classes, prototypes and functions (all of which may be
  58.  * specifically turned on and off.  The performance cost for this level of
  59.  * accuracyis not trivial.  This parser knows a lot about the syntax of C and
  60.  * takes a fair amount of time.  You should expect to see a file complete
  61.  * somewhere in the range of 125%-150% of the time as Lugaru's tagger for C.
  62.  * This is not only because of the detail of the tags but also the larger
  63.  * number of them.  This tagger is not intended to do all of your work for
  64.  * you but is designed to be used in conjunction with the tags generator I
  65.  * have developed and is now available.  This file implements the same
  66.  * lexical and semantic parser as is found in that executable.  Use the
  67.  * executable in your make file for very fast and updated tags.  If you have
  68.  * problems finding it, contact me and I can point the way...
  69.  *
  70.  * There is defined at the end of this module a when_loading() function which
  71.  * alters the default search case map to allow *correct* (or at least
  72.  * consistent sorting with sort routines external to Epsilon.  In particular,
  73.  * to produce the same sort order as any UNIX, VMS or HP style sort or with
  74.  * the tags generator this module is supposed to coexist with this mapping
  75.  * must be done.  You should see no difference in the location of sorted
  76.  * buffers except for lines starting with ^, [, \, ] and _.
  77.  *
  78.  * This code is dedicated to the public domain with the caveat that Lugaru is
  79.  * welcome to use this within their distribution source code which is
  80.  * supplied with Epsilon.
  81.  *
  82.  * Good Tagging,
  83.  *
  84.  *      jbk@wrq.com
  85.  *
  86.  *      John Kercheval
  87.  *      127 NW Bowdoin Pl #105
  88.  *      Seattle, WA  98107-4960
  89.  *      September 8, 1991
  90.  */
  91.  
  92. #include <eel.h>
  93.  
  94. #define BOOLEAN int
  95. #define TRUE 1
  96. #define FALSE 0
  97.  
  98. #define CBUFSIZE 4096
  99. #define MAX_TOKEN_LENGTH 4096
  100.  
  101.  
  102. /* the following variable determine the behavior of the parser with respect
  103.  * to the token types which are output as a tag.  Note that use of the
  104.  * CTagWantExtern variable is a modifier and will only be effective when
  105.  * other options are used (ie. CTagWantProtoType must be specified to obtain
  106.  * extern prototypes, CTagWantExtern alone yields nothing).  Note also that
  107.  * the CTagWantExtern modifier has no effect for function, define and macro
  108.  * tags which are tagged only according only to the CTagWantFunction,
  109.  * CTagWantDefine and CTagWantMacro variables respectively.  CTagWantStatic
  110.  * is also a modifier and will allow tags of internal statically defined
  111.  * variables and other declarations.  CTagWantStatic also has no effect on
  112.  * Define and Macro tags.
  113.  */
  114. BOOLEAN CTagWantFunction = TRUE;
  115. BOOLEAN CTagWantProtoType = FALSE;
  116. BOOLEAN CTagWantStructure = TRUE;
  117. BOOLEAN CTagWantTypeDefinition = TRUE;
  118. BOOLEAN CTagWantMacro = TRUE;
  119. BOOLEAN CTagWantEnumeration = TRUE;
  120. BOOLEAN CTagWantEnumerationConstant = TRUE;
  121. BOOLEAN CTagWantUnion = TRUE;
  122. BOOLEAN CTagWantGlobalVariable = TRUE;
  123. BOOLEAN CTagWantClass = TRUE;
  124. BOOLEAN CTagWantDefine = TRUE;
  125. BOOLEAN CTagWantExtern = FALSE;
  126. BOOLEAN CTagWantStatic = TRUE;
  127.  
  128.  
  129. /* function for determining if character is whitespace */
  130. #define IsWhite(c) ( _C_white_boolean_table[c] )
  131.  
  132. /* the indexed table for white space character lookup */
  133. BOOLEAN _C_white_boolean_table[256];
  134.  
  135. /* list of whitespace characters */
  136. char C_white[] = " \f\t\n\r";
  137.  
  138.  
  139. /* function for determining if character is a delimiter */
  140. #define IsDelim(c) ( _C_delim_boolean_table[c] )
  141.  
  142. /* the indexed table for token delimiter lookup */
  143. BOOLEAN _C_delim_boolean_table[256];
  144.  
  145. /* list of token delimiters */
  146. char C_delim[] = " \f\t\n\r\"[](){}#;:,.'=-+*/%&|^~!<>?";
  147.  
  148.  
  149. /* function for determining if character is a puncuator */
  150. #define IsPunctuator(c) ( _C_punctuator_boolean_table[c] )
  151.  
  152. /* the indexed table for punctuator character lookup */
  153. BOOLEAN _C_punctuator_boolean_table[256];
  154.  
  155. /* list of punctuators */
  156. char C_declaration_delim[] = "[](){},;=";
  157.  
  158.  
  159. char C_open_brace[] = "{[(";    /* open brace set */
  160. char C_close_brace[] = ")]}";   /* close brace set */
  161.  
  162.  
  163. /*
  164.  * These defines are used to denote the type of the current tag
  165.  */
  166. #define NOP 0
  167. #define Function 1
  168. #define ProtoType 2
  169. #define Structure 3
  170. #define TypeDefinition 4
  171. #define Macro 5
  172. #define Enumeration 6
  173. #define EnumerationConstant 7
  174. #define Union 8
  175. #define GlobalVariable 9
  176. #define Class 10
  177. #define Define 11
  178. #define Extern 12
  179. #define Static 13
  180.  
  181. /* convenient definition */
  182. typedef int SymbolType;
  183.  
  184.  
  185. /* the current file buffer state */
  186. typedef struct BufferStruct {
  187.     int token_line_location;    /* current token line in buffer */
  188.     char *inbuf;                /* the buffer currently being parsed */
  189. } Buffer;
  190.  
  191.  
  192. /* the current input token state */
  193. typedef struct TokenStruct {
  194.     char sbuf1[MAX_TOKEN_LENGTH];       /* the first token buffer */
  195.     int charloc1;               /* the char location of sbuf1 */
  196.     int tokenline1;             /* the line number of sbuf1 */
  197.  
  198.     char sbuf2[MAX_TOKEN_LENGTH];       /* the second token buffer */
  199.     int charloc2;               /* the char location of sbuf2 */
  200.     int tokenline2;             /* the line number of sbuf2 */
  201.  
  202.     char *cur_token;            /* pointer to the current token buffer */
  203.     int *cur_char_location;     /* the location of current token */
  204.     int *cur_token_line;        /* the line of the current token */
  205.  
  206.     char *prev_token;           /* pointer to the last token buffer */
  207.     int *prev_char_location;    /* the location of previous token */
  208.     int *prev_token_line;       /* the line of the previous token */
  209.  
  210.     int token_count;            /* temporary variable, used by ToPunctuator */
  211.     int else_nesting_level;     /* the current nesting level */
  212.  
  213.     BOOLEAN extern_active;      /* minor state for this statement */
  214.     BOOLEAN static_active;      /* minor state for this statement */
  215. } Token;
  216.  
  217.  
  218. #define SYMBOL_SIZE 20
  219.  
  220. /* a list of known C tokens and keywords */
  221. char C_token_list[][SYMBOL_SIZE] =
  222. {
  223.     "*ivclsdfuaretp_hn",        /* list of starting characters of symbols
  224.                                  * below */
  225.     "*",                        /* pointer */
  226.     "int",                      /* integer declaration */
  227.     "void",                     /* void type */
  228.     "char",                     /* character */
  229.     "long",                     /* long integer */
  230.     "short",                    /* short integer */
  231.     "double",                   /* double floating point */
  232.     "float",                    /* floating point */
  233.     "signed",                   /* signed integer */
  234.     "unsigned",                 /* unsigned integer */
  235.     "auto",                     /* auto variable (local duration) */
  236.     "register",                 /* register variable */
  237.     "static",                   /* static variable */
  238.     "struct",                   /* structure define */
  239.     "union",                    /* union define */
  240.     "enum",                     /* enum defined */
  241.     "typedef",                  /* type definition */
  242.     "const",                    /* constant variable */
  243.     "extern",                   /* external declaration */
  244.     "class",                    /* class declaration */
  245.     "friend",                   /* class modifier */
  246.     "private",                  /* class modifier */
  247.     "protected",                /* class modifier */
  248.     "public",                   /* class modifier */
  249.     "volatile",                 /* Compiler warning */
  250.     "_based",                   /* pointer type */
  251.     "_cdecl",                   /* parameter calling sequence, C style */
  252.     "cdecl",                    /* parameter calling sequence, C style */
  253.     "_far",                     /* pointer type */
  254.     "far",                      /* pointer type */
  255.     "_huge",                    /* pointer type */
  256.     "huge",                     /* pointer type */
  257.     "_near",                    /* pointer type */
  258.     "near",                     /* pointer type */
  259.     "_pascal",                  /* parameter calling sequence, PASCAL style */
  260.     "pascal",                   /* parameter calling sequence, PASCAL style */
  261.     "_fortran",                 /* parameter calling sequence, FORTRAN style */
  262.     "_fastcall",                /* parameter calling sequence, via registers */
  263.     "\0"
  264. };
  265.  
  266.  
  267. /*----------------------------------------------------------------------------
  268.  *
  269.  * CParserInit() initializes the tables required by the parser. The tables
  270.  * used are a simple boolean index which are true if the character
  271.  * corresponding to the index is a member of the associated table.
  272.  *
  273.  ---------------------------------------------------------------------------*/
  274.  
  275. CParserInit()
  276. {
  277.     char *s;
  278.     int i;
  279.  
  280.     /* init the entire block to FALSE */
  281.     for (i = 0; i < 256; i++) {
  282.         _C_delim_boolean_table[i] = FALSE;
  283.         _C_white_boolean_table[i] = FALSE;
  284.         _C_punctuator_boolean_table[i] = FALSE;
  285.     }
  286.  
  287.     /* set the characters in the delim set to TRUE */
  288.     for (s = C_delim; *s; s++) {
  289.         _C_delim_boolean_table[*s] = TRUE;
  290.     }
  291.  
  292.     /* set the characters in the white set to TRUE */
  293.     for (s = C_white; *s; s++) {
  294.         _C_white_boolean_table[*s] = TRUE;
  295.     }
  296.  
  297.     /* set the characters in the punctuator set to TRUE */
  298.     for (s = C_declaration_delim; *s; s++) {
  299.         _C_punctuator_boolean_table[*s] = TRUE;
  300.     }
  301. }
  302.  
  303.  
  304. /*----------------------------------------------------------------------------
  305.  *
  306.  * strchr() is the standard string library function strchr()
  307.  *
  308.  ---------------------------------------------------------------------------*/
  309.  
  310. char *strchr(s, c)
  311.     char *s;
  312.     char c;
  313. {
  314.     char *ret = s;
  315.  
  316.     while (*ret) {
  317.         if (*ret == c)
  318.             return ret;
  319.         ret++;
  320.     }
  321.  
  322.     if (*ret == c)
  323.         return ret;
  324.  
  325.     return NULL;
  326. }
  327.  
  328.  
  329. /*----------------------------------------------------------------------------
  330.  *
  331.  * FillBuffer() fills the passed buffer parameter with bufsize characters
  332.  * (or as many as are available) and places and null character '\0' at the
  333.  * end of the buffer.  This routine returns TRUE if successful and FALSE if
  334.  * eof(infile) is true.  Note: if a bufsize parameter is passed and the read
  335.  * is successful for bufsize characters, then buffer[bufsize] will be
  336.  * overwritten with the null character.  Do not pass a bufsize the maximum
  337.  * size of the buffer.  This null terminated buffering scheme assumes the
  338.  * source file has no null character embedded within it.
  339.  *
  340.  ---------------------------------------------------------------------------*/
  341.  
  342. BOOLEAN FillBuffer(inbuf, ctag_buffer, bufsize)
  343.     char *inbuf;
  344.     char *ctag_buffer;
  345.     int bufsize;
  346. {
  347.     char *old_buf;
  348.     int new_point;
  349.  
  350.     /* init buffer */
  351.     *ctag_buffer = '\0';
  352.  
  353.     /* go to the input buffer */
  354.     old_buf = bufname;
  355.     bufname = inbuf;
  356.  
  357.     /* return if end of buffer */
  358.     if (point == size())
  359.         return FALSE;
  360.  
  361.     /* read the buffer from the file */
  362.     if (point + bufsize > size()) {
  363.         new_point = size();
  364.     }
  365.     else {
  366.         new_point = point + bufsize;
  367.     }
  368.     grab(point, new_point, ctag_buffer);
  369.  
  370.     /* place the end of buffer mark, adjust point and return success */
  371.     ctag_buffer[new_point - point] = '\0';
  372.     point = new_point;
  373.     return TRUE;
  374. }
  375.  
  376.  
  377. /*----------------------------------------------------------------------------
  378.  *
  379.  * CSymbolWanted() returns true if flags are true for the symbol type passed
  380.  * and false otherwise.
  381.  *
  382.  ---------------------------------------------------------------------------*/
  383.  
  384. BOOLEAN CSymbolWanted(type)
  385.     SymbolType type;
  386. {
  387.     switch (type) {
  388.         case Function:
  389.             return CTagWantFunction;
  390.             break;
  391.         case ProtoType:
  392.             return CTagWantProtoType;
  393.             break;
  394.         case GlobalVariable:
  395.             return CTagWantGlobalVariable;
  396.             break;
  397.         case Define:
  398.             return CTagWantDefine;
  399.             break;
  400.         case Macro:
  401.             return CTagWantMacro;
  402.             break;
  403.         case Structure:
  404.             return CTagWantStructure;
  405.             break;
  406.         case TypeDefinition:
  407.             return CTagWantTypeDefinition;
  408.             break;
  409.         case Enumeration:
  410.             return CTagWantEnumeration;
  411.             break;
  412.         case EnumerationConstant:
  413.             return CTagWantEnumerationConstant;
  414.             break;
  415.         case Union:
  416.             return CTagWantUnion;
  417.             break;
  418.         case Class:
  419.             return CTagWantClass;
  420.             break;
  421.         default:
  422.             return FALSE;
  423.             break;
  424.     }
  425. }
  426.  
  427.  
  428. /*----------------------------------------------------------------------------
  429.  *
  430.  * CTokenType() takes the token passed and determines if the token is a
  431.  * special token.  Special tokens require specialized handling in the parser.
  432.  * The function returns the type of token according to the SymbolTypeEnum
  433.  * enumeration.  This routine can only tell so much from one symbol but will
  434.  * return some type for all the *interesting* tokens.  Anything that is
  435.  * loosely defined is given back with the closest type available and the
  436.  * parser must give it contextual meaning
  437.  *
  438.  ---------------------------------------------------------------------------*/
  439.  
  440. SymbolType CTokenType(token)
  441.     char *token;
  442. {
  443.     /* look for dirty rejection */
  444.     if (!strchr("cestu#", token[0]))
  445.         return NOP;
  446.  
  447.     /* macro and non macro defines */
  448.     if (!strcmp(token, "#"))
  449.         return Define;
  450.  
  451.     /* structure declarations */
  452.     if (!strcmp(token, "struct"))
  453.         return Structure;
  454.  
  455.     /* type declaration */
  456.     if (!strcmp(token, "typedef"))
  457.         return TypeDefinition;
  458.  
  459.     /* enumeration declaration */
  460.     if (!strcmp(token, "enum"))
  461.         return Enumeration;
  462.  
  463.     /* union declaration */
  464.     if (!strcmp(token, "union"))
  465.         return Union;
  466.  
  467.     /* class declaration */
  468.     if (!strcmp(token, "class"))
  469.         return Class;
  470.  
  471.     /* external declaration */
  472.     if (!strcmp(token, "extern"))
  473.         return Extern;
  474.  
  475.     /* static declaration */
  476.     if (!strcmp(token, "static"))
  477.         return Static;
  478.  
  479.     /* do not recognize it as anything special */
  480.     return NOP;
  481. }
  482.  
  483.  
  484. /*----------------------------------------------------------------------------
  485.  *
  486.  * CIsDeclarationToken() takes the token passed and determines if the token
  487.  * is a declaration keyword used in C.  The user may define new declaration
  488.  * keywords via use of the typedef keyword.  This alters the syntax of C.  If
  489.  * the syntax is changed in this way it is probable that this routine would
  490.  * not return the correct value.  For the standard uses of this routine that
  491.  * information should not hinder performance for the vast majority of the
  492.  * cases.
  493.  *
  494.  ---------------------------------------------------------------------------*/
  495.  
  496. BOOLEAN CIsDeclarationToken(token)
  497.     char *token;
  498. {
  499.     int index;
  500.  
  501.     /* look for dirty rejection */
  502.     if (!strchr(C_token_list[0], token[0]))
  503.         return FALSE;
  504.  
  505.     /* march through array until membership is determined */
  506.     for (index = 1; *C_token_list[index]; (index)++) {
  507.  
  508.         /* return true if token found */
  509.         if (!strcmp(token, C_token_list[index])) {
  510.             return TRUE;
  511.         }
  512.     }
  513.  
  514.     /* did not find it */
  515.     return FALSE;
  516. }
  517.  
  518.  
  519. /*----------------------------------------------------------------------------
  520.  *
  521.  * COutputToken() will output a token of a given type.  The token is output
  522.  * if the passed token type is requested from the command line.
  523.  *
  524.  ---------------------------------------------------------------------------*/
  525.  
  526. COutputToken(token, token_buffer, token_type, infname, outbuf)
  527.     Token *token;
  528.     Buffer *token_buffer;
  529.     SymbolType token_type;
  530.     char *infname;
  531.     char *outbuf;
  532. {
  533.     /* check that the symbol is wanted and output it if so */
  534.     if (CSymbolWanted(token_type)) {
  535.  
  536.         if (token->extern_active) {
  537.             if (!CTagWantExtern) {
  538.                 if (token_type != Function &&
  539.                     token_type != Define &&
  540.                     token_type != Macro) {
  541.                     return;
  542.                 }
  543.             }
  544.         }
  545.         /* return if statics are not wanted */
  546.         if (token->static_active) {
  547.             if (!CTagWantStatic) {
  548.                 if (token_type != Define &&
  549.                     token_type != Macro) {
  550.                     return;
  551.                 }
  552.             }
  553.         }
  554.         add_tag(token->prev_token, infname,
  555.                 *(token->prev_char_location) -
  556.                 strlen(token->prev_token));
  557.     }
  558. }
  559.  
  560.  
  561. /*----------------------------------------------------------------------------
  562.  *
  563.  * CGetToken() will obtain the next token in the line pointed to by lptr
  564.  * and in addition will return FALSE if EOL is reached or a comment character
  565.  * is the first non whitespace character found.  This routine is passed an
  566.  * inbut buffer (Cbuf) and a current pointer into the buffer.  It is the
  567.  * responsibility of this routine to refill the buffer if required.  Quoted
  568.  * strings and single quoted characters are returned as a single token.
  569.  * Comments are completely ignored by this parser.  The token will not exceed
  570.  * max_token_length - 1 in length (not including the end of line delimiter)
  571.  *
  572.  ---------------------------------------------------------------------------*/
  573.  
  574. BOOLEAN CGetToken(inbuf, token, max_token_length, line_number)
  575.     char *inbuf;
  576.     char *token;
  577.     int max_token_length;
  578.     int *line_number;
  579. {
  580.     /* a state of the lexical parser */
  581. #define Parse 0
  582. #define BeginCommentMaybe 1
  583. #define InComment 2
  584. #define InCommentEndMaybe 3
  585. #define InCPPComment 4
  586. #define InQuoteNormal 5
  587. #define InQuoteLiteral 6
  588. #define InSingleQuoteNormal 7
  589. #define InSingleQuoteLiteral 8
  590. #define EndSingleQuote 9
  591. #define WhiteSpace 10
  592. #define Exit 11
  593.  
  594.     typedef int State;
  595.  
  596.     State current_state;        /* the current state of the parser */
  597.  
  598.     char c;                     /* the current character being examined */
  599.     char *t;                    /* pointer into token */
  600.  
  601.     int token_length;           /* the current token_length cannot exceed
  602.                                  * max token length */
  603.  
  604.     /* init */
  605.     current_state = WhiteSpace;
  606.     t = token;
  607.     *t = '\0';
  608.     token_length = 0;
  609.  
  610.     /* parse the file for the next token */
  611.     while (TRUE) {
  612.  
  613.         /* if the buffer has been completely used, return FALSE */
  614.         if (point == size())
  615.             return FALSE;
  616.  
  617.         c = curchar();
  618.         point++;
  619.  
  620.         /* react on the state machine */
  621.         switch (current_state) {
  622.  
  623.             case Parse:
  624.                 switch (c) {
  625.  
  626.                     case '/':
  627.  
  628.                         /* return if we already have a token */
  629.                         if (t != token) {
  630.                             point--;
  631.                             current_state = Exit;
  632.                         }
  633.                         else {
  634.                             /* this may be the begin if a comment or the
  635.                              * division symbol, read the next character after
  636.                              * verifying it the buffer doesn't need refilling */
  637.                             current_state = BeginCommentMaybe;
  638.                             *t = c;
  639.                         }
  640.                         break;
  641.  
  642.                     case '\"':
  643.  
  644.                         /* return if we already have a token */
  645.                         if (t != token) {
  646.                             point--;
  647.                             current_state = Exit;
  648.                         }
  649.                         else {
  650.                             current_state = InQuoteNormal;
  651.                             *t++ = c;
  652.                             token_length++;
  653.                         }
  654.                         break;
  655.  
  656.                     case '\'':
  657.  
  658.                         /* return if we already have a token */
  659.                         if (t != token) {
  660.                             point--;
  661.                             current_state = Exit;
  662.                         }
  663.                         else {
  664.                             current_state = InSingleQuoteNormal;
  665.                             *t++ = c;
  666.                             token_length++;
  667.                         }
  668.                         break;
  669.  
  670.                     default:
  671.  
  672.                         /* if it is a delimiter than stop processing */
  673.                         if (IsDelim(c)) {
  674.  
  675.                             /* if a token exists then back up in buffer */
  676.                             if (t != token) {
  677.                                 point--;
  678.                             }
  679.                             else {
  680.                                 *t++ = c;
  681.                                 token_length++;
  682.                             }
  683.                             current_state = Exit;
  684.                         }
  685.                         else {
  686.  
  687.                             /* normal character, store it in the token */
  688.                             *t++ = c;
  689.                             token_length++;
  690.                         }
  691.                         break;
  692.                 }
  693.                 break;
  694.  
  695.             case WhiteSpace:
  696.  
  697.                 /* pass over whitespace, backup one char if no longer in
  698.                  * white space region */
  699.                 if (!IsWhite(c)) {
  700.                     current_state = Parse;
  701.                     point--;
  702.                 }
  703.                 else {
  704.  
  705.                     /* check for newline */
  706.                     if (c == '\n') {
  707.                         (*line_number)++;
  708.                     }
  709.                 }
  710.                 break;
  711.  
  712.             case BeginCommentMaybe:
  713.                 switch (c) {
  714.  
  715.                     case '/':
  716.                         current_state = InCPPComment;
  717.                         break;
  718.  
  719.                     case '*':
  720.                         current_state = InComment;
  721.                         break;
  722.  
  723.                     default:
  724.                         t++;
  725.                         token_length++;
  726.                         point--;
  727.                         current_state = Exit;
  728.                         break;
  729.                 }
  730.                 break;
  731.  
  732.             case InComment:
  733.                 switch (c) {
  734.  
  735.                     case '*':
  736.                         /* this is potentially the end of the comment */
  737.                         current_state = InCommentEndMaybe;
  738.                         break;
  739.  
  740.                     case '\n':
  741.                         /* new line just increment state variables */
  742.                         (*line_number)++;
  743.                         break;
  744.  
  745.                     default:
  746.                         break;
  747.                 }
  748.                 break;
  749.  
  750.             case InCommentEndMaybe:
  751.                 switch (c) {
  752.  
  753.                     case '/':
  754.                         /* this is indeed the end of the comment */
  755.                         current_state = WhiteSpace;
  756.                         break;
  757.  
  758.                     case '*':
  759.                         /* this is also perhaps the end of comment */
  760.                         break;
  761.  
  762.                     case '\n':
  763.                         /* new line just increment state variables */
  764.                         (*line_number)++;
  765.  
  766.                     default:
  767.                         /* still part of the current comment */
  768.                         current_state = InComment;
  769.                         break;
  770.                 }
  771.                 break;
  772.  
  773.             case InCPPComment:
  774.                 if (c == '\n') {
  775.                     current_state = WhiteSpace;
  776.                     (*line_number)++;
  777.                 }
  778.                 break;
  779.  
  780.             case InQuoteNormal:
  781.                 switch (c) {
  782.  
  783.                     case '\"':
  784.                         /* end of InQuoteNormal state */
  785.                         current_state = Exit;
  786.                         break;
  787.  
  788.                     case '\\':
  789.                         /* InQuoteLiteral state */
  790.                         current_state = InQuoteLiteral;
  791.                         break;
  792.  
  793.                     default:
  794.                         /* normal dull behavior */
  795.                         break;
  796.                 }
  797.                 *t++ = c;
  798.                 token_length++;
  799.                 break;
  800.  
  801.             case InQuoteLiteral:
  802.                 /* this char is simply copied */
  803.                 current_state = InQuoteNormal;
  804.                 *t++ = c;
  805.                 token_length++;
  806.                 break;
  807.  
  808.             case InSingleQuoteNormal:
  809.                 switch (c) {
  810.  
  811.                     case '\\':
  812.                         /* InQuoteLiteral state */
  813.                         current_state = InSingleQuoteLiteral;
  814.                         break;
  815.  
  816.                     default:
  817.                         /* Just copy the character and move to close quote */
  818.                         current_state = EndSingleQuote;
  819.                         break;
  820.                 }
  821.                 *t++ = c;
  822.                 token_length++;
  823.                 break;
  824.  
  825.             case InSingleQuoteLiteral:
  826.                 /* this char is simply copied */
  827.                 current_state = EndSingleQuote;
  828.                 *t++ = c;
  829.                 token_length++;
  830.                 break;
  831.  
  832.             case EndSingleQuote:
  833.  
  834.                 /* end of InSingleQuote states */
  835.                 current_state = Exit;
  836.                 *t++ = c;
  837.                 token_length++;
  838.                 break;
  839.  
  840.             case Exit:
  841.                 *t = '\0';
  842.                 point--;
  843.                 return TRUE;
  844.                 break;
  845.  
  846.             default:            /* not reached */
  847.                 break;
  848.         }
  849.  
  850.         /* if the token_length has gotten too large then return */
  851.         if (token_length == max_token_length - 1) {
  852.             *t = '\0';
  853.             point--;
  854.             return TRUE;
  855.         }
  856.     }
  857. }
  858.  
  859.  
  860. /*----------------------------------------------------------------------------
  861.  *
  862.  * CFillToken() will obtain the next lexical parser from the buffer and move
  863.  * the token into the Token structure.  TRUE is returned if the lexical
  864.  * parser returns TRUE, otherwise FALSE is returned.
  865.  *
  866.  ---------------------------------------------------------------------------*/
  867.  
  868. BOOLEAN CFillToken(token, token_buffer)
  869.     Token *token;
  870.     Buffer *token_buffer;
  871. {
  872.     BOOLEAN token_found;
  873.  
  874.     /* obtain the next token */
  875.     token_found = CGetToken(token_buffer->inbuf,
  876.                             token->cur_token,
  877.                             MAX_TOKEN_LENGTH,
  878.                             &(token_buffer->token_line_location));
  879.  
  880.     /* if one is around then update the state for that token */
  881.     if (token_found) {
  882.         /* update location variables */
  883.         *(token->cur_char_location) = point;
  884.         *(token->cur_token_line) = token_buffer->token_line_location;
  885.     }
  886.  
  887.     return token_found;
  888. }
  889.  
  890.  
  891. /*----------------------------------------------------------------------------
  892.  *
  893.  * CTokenSwap() will swap the token variables and set the prev_ variables
  894.  * correctly
  895.  *
  896.  ---------------------------------------------------------------------------*/
  897.  
  898. CTokenSwap(token)
  899.     Token *token;
  900. {
  901.     char *charswap;             /* temporary swap variable */
  902.     int *longintswap;           /* temporary swap variable */
  903.  
  904.     /* swap the active token string */
  905.     charswap = token->cur_token;
  906.     token->cur_token = token->prev_token;
  907.     token->prev_token = charswap;
  908.  
  909.     /* swap the active character location */
  910.     longintswap = token->cur_char_location;
  911.     token->cur_char_location = token->prev_char_location;
  912.     token->prev_char_location = longintswap;
  913.  
  914.     /* swap the active line */
  915.     longintswap = token->cur_token_line;
  916.     token->cur_token_line = token->prev_token_line;
  917.     token->prev_token_line = longintswap;
  918. }
  919.  
  920.  
  921. /*----------------------------------------------------------------------------
  922.  *
  923.  * CDiscardLine() will move past all the characters up to the next EOL that
  924.  * is not preceded by a line continuation character.  This routine will
  925.  * return TRUE if there was a '(' character as the first character.  This
  926.  * return value is useful for determining if #defines are macros or simple
  927.  * defines.
  928.  *
  929.  ---------------------------------------------------------------------------*/
  930.  
  931. BOOLEAN CDiscardLine(inbuf, line_number)
  932.     char *inbuf;
  933.     int *line_number;
  934. {
  935.     char c;                     /* the current character being examined */
  936.  
  937.     BOOLEAN line_continue;      /* TRUE if line continuation true */
  938.     BOOLEAN is_macro;           /* TRUE if the first delimiter char is '(' */
  939.     BOOLEAN first_char;         /* TRUE when first character is active */
  940.  
  941.     /* init */
  942.     c = '\0';
  943.     line_continue = FALSE;
  944.     is_macro = FALSE;
  945.     first_char = TRUE;
  946.  
  947.     /* if the end of buffer is reached then return */
  948.     if (point == size())
  949.         return is_macro;
  950.  
  951.     /* loop until non continued EOL encountered */
  952.     do {
  953.  
  954.         /* determine if the first character is a '(' */
  955.         if (first_char) {
  956.             if (c == '(')
  957.                 is_macro = TRUE;
  958.             first_char = FALSE;
  959.         }
  960.  
  961.         /* handle the newline */
  962.         if (c == '\n') {
  963.             line_continue = FALSE;
  964.             (*line_number)++;
  965.         }
  966.  
  967.         c = curchar();
  968.         point++;
  969.  
  970.         if (c == '\\')
  971.             line_continue = TRUE;
  972.  
  973.  
  974.     } while (c != '\n' || line_continue);
  975.  
  976.     (*line_number)++;
  977.     return is_macro;
  978. }
  979.  
  980.  
  981. /*----------------------------------------------------------------------------
  982.  *
  983.  * CParseDefine() will parse macros and defines in standard C syntax
  984.  * distinguish between a macro and a define, if there is a punctuator '(',
  985.  * then it is a macro.  Take the token just before the first space or
  986.  * punctuator
  987.  *
  988.  ---------------------------------------------------------------------------*/
  989.  
  990. CParseDefine(token, token_buffer, infname, outbuf)
  991.     Token *token;
  992.     Buffer *token_buffer;
  993.     char *infname;
  994.     char *outbuf;
  995. {
  996.     SymbolType tmptype;         /* a temporay type variable */
  997.  
  998.     BOOLEAN token_found;
  999.     BOOLEAN is_macro;
  1000.  
  1001.     token_found = CFillToken(token, token_buffer);
  1002.     if (token_found) {
  1003.  
  1004.         /* save the previous values */
  1005.         CTokenSwap(token);
  1006.  
  1007.  
  1008.         /* get rid of the rest of the line and return the define type */
  1009.         is_macro =
  1010.             CDiscardLine(token_buffer->inbuf,
  1011.                          &(token_buffer->token_line_location));
  1012.  
  1013.         /* react on the token */
  1014.         if (is_macro) {
  1015.             tmptype = Macro;
  1016.         }
  1017.         else {
  1018.             tmptype = Define;
  1019.         }
  1020.  
  1021.         /* output the token */
  1022.         COutputToken(token, token_buffer, tmptype,
  1023.                      infname, outbuf);
  1024.     }
  1025. }
  1026.  
  1027.  
  1028. /*----------------------------------------------------------------------------
  1029.  *
  1030.  * CParsePreprocessorDirective() will parse preprocessor directives in
  1031.  * standard C syntax
  1032.  *
  1033.  ---------------------------------------------------------------------------*/
  1034.  
  1035. CParsePreprocessorDirective(token, token_buffer, infname, outbuf)
  1036.     Token *token;
  1037.     Buffer *token_buffer;
  1038.     char *infname;
  1039.     char *outbuf;
  1040. {
  1041.     BOOLEAN token_found;
  1042.  
  1043.     token_found = CFillToken(token, token_buffer);
  1044.     if (token_found) {
  1045.  
  1046.         /* deal with a define directive */
  1047.         if (!strcmp(token->cur_token, "define")) {
  1048.             CParseDefine(token, token_buffer, infname, outbuf);
  1049.         }
  1050.         else {
  1051.  
  1052.             /* increment the else block level pointer */
  1053.             if (!strcmp(token->cur_token, "else")) {
  1054.                 token->else_nesting_level++;
  1055.             }
  1056.             else {
  1057.  
  1058.                 /* decrement the else block level pointer */
  1059.                 if (!strcmp(token->cur_token, "endif")) {
  1060.                     if (token->else_nesting_level)
  1061.                         token->else_nesting_level--;
  1062.                 }
  1063.                 else {
  1064.  
  1065.                     /* if an else has not already been seen then increment
  1066.                      * the level */
  1067.                     if (!strcmp(token->cur_token, "elif")) {
  1068.                         token->else_nesting_level++;
  1069.                     }
  1070.                 }
  1071.             }
  1072.  
  1073.             /* remove the rest of the directive line including line
  1074.              * continuation characters */
  1075.             CDiscardLine(token_buffer->inbuf,
  1076.                          &(token_buffer->token_line_location));
  1077.         }
  1078.     }
  1079. }
  1080.  
  1081.  
  1082. /*----------------------------------------------------------------------------
  1083.  *
  1084.  * CNextToken() will obtain the next token in the buffer and update the
  1085.  * appropriate variables.
  1086.  *
  1087.  ---------------------------------------------------------------------------*/
  1088.  
  1089. BOOLEAN CNextToken(token, token_buffer, infname, outbuf)
  1090.     Token *token;
  1091.     Buffer *token_buffer;
  1092.     char *infname;
  1093.     char *outbuf;
  1094. {
  1095.     BOOLEAN token_found;
  1096.     BOOLEAN cycle;
  1097.  
  1098.     do {
  1099.         /* obtain the next token */
  1100.         token_found = CFillToken(token, token_buffer);
  1101.  
  1102.         /* check for preprocessing directives and parse them if found */
  1103.         if (token->cur_token[0] == '#' && token_found) {
  1104.  
  1105.             /* parse the directive and loop back to get another token */
  1106.             CParsePreprocessorDirective(token, token_buffer, infname, outbuf);
  1107.             cycle = TRUE;
  1108.         }
  1109.         else {
  1110.  
  1111.             /* we found a token to pass to the semantic parser */
  1112.             cycle = FALSE;
  1113.         }
  1114.     } while (cycle);
  1115.  
  1116.     /* return it */
  1117.     return token_found;
  1118. }
  1119.  
  1120.  
  1121. /*----------------------------------------------------------------------------
  1122.  *
  1123.  * CToLevelZero() will increment the nesting level and then parse tokens
  1124.  * until level zero has been reached again.  If tokens are no longer
  1125.  * available this loop will stop.
  1126.  *
  1127.  ---------------------------------------------------------------------------*/
  1128.  
  1129. CToLevelZero(token, token_buffer, infname, outbuf)
  1130.     Token *token;
  1131.     Buffer *token_buffer;
  1132.     char *infname;
  1133.     char *outbuf;
  1134. {
  1135.     int nesting_level = 1;
  1136.  
  1137.     token->else_nesting_level = 0;
  1138.  
  1139.     while (nesting_level) {
  1140.         if (CGetToken(token_buffer->inbuf, token->cur_token,
  1141.                       MAX_TOKEN_LENGTH,
  1142.                       &(token_buffer->token_line_location))) {
  1143.             if (token->cur_token[0] == '#') {
  1144.                 CParsePreprocessorDirective(token, token_buffer,
  1145.                                             infname, outbuf);
  1146.             }
  1147.             else {
  1148.  
  1149.                 /* only count open brace, parens and brackets within blocks
  1150.                  * of one element of an ifdef code block */
  1151.                 if (!token->else_nesting_level) {
  1152.                     if (strchr(C_open_brace, token->cur_token[0]))
  1153.                         nesting_level++;
  1154.                     else
  1155.                         if (strchr(C_close_brace, token->cur_token[0]))
  1156.                             nesting_level--;
  1157.                 }
  1158.             }
  1159.         }
  1160.         else
  1161.             nesting_level = 0;
  1162.     }
  1163. }
  1164.  
  1165.  
  1166. /*----------------------------------------------------------------------------
  1167.  *
  1168.  * CToPunctuator() will parse tokens until the next punctuator has been
  1169.  * reached.  If tokens are no longer available this loop will stop.  If this
  1170.  * loop is successful the found flag declared in the host routine will be
  1171.  * set.
  1172.  *
  1173.  ---------------------------------------------------------------------------*/
  1174.  
  1175. BOOLEAN CToPunctuator(token, token_buffer, infname, outbuf)
  1176.     Token *token;
  1177.     Buffer *token_buffer;
  1178.     char *infname;
  1179.     char *outbuf;
  1180. {
  1181.     BOOLEAN punctuator_found;
  1182.  
  1183.     /* init and parse through until the first punctuator is found */
  1184.     token->token_count = 0;
  1185.     punctuator_found = FALSE;
  1186.     while (!punctuator_found) {
  1187.         token->token_count++;
  1188.         CTokenSwap(token);
  1189.         if (!CNextToken(token, token_buffer, infname, outbuf)) {
  1190.             break;
  1191.         }
  1192.         else {
  1193.             if (IsPunctuator(token->cur_token[0]))
  1194.                 punctuator_found = TRUE;
  1195.         }
  1196.     }
  1197.  
  1198.     /* return value */
  1199.     return punctuator_found;
  1200. }
  1201.  
  1202.  
  1203. /*----------------------------------------------------------------------------
  1204.  *
  1205.  * CParseParens() will move through a declaration in parentheses and place
  1206.  * the correct valid token as prev_token.  This return TRUE if a '[' was seen
  1207.  * within the parens and false otherwise.
  1208.  *
  1209.  ---------------------------------------------------------------------------*/
  1210.  
  1211. BOOLEAN CParseParens(token, token_buffer, infname, outbuf)
  1212.     Token *token;
  1213.     Buffer *token_buffer;
  1214.     char *infname;
  1215.     char *outbuf;
  1216. {
  1217.     BOOLEAN token_found;
  1218.     BOOLEAN variable_seen;
  1219.     int brace_ignore = 1;
  1220.  
  1221.     token->else_nesting_level = 0;
  1222.  
  1223.     token_found = TRUE;
  1224.     variable_seen = FALSE;
  1225.     while (brace_ignore &&
  1226.            token_found) {
  1227.  
  1228.         token_found = CNextToken(token, token_buffer, infname, outbuf);
  1229.  
  1230.         if (token_found &&
  1231.             !token->else_nesting_level) {
  1232.             switch (token->cur_token[0]) {
  1233.  
  1234.                 case '(':
  1235.  
  1236.                     /* increment brace_ignore and continue */
  1237.                     brace_ignore++;
  1238.                     break;
  1239.  
  1240.                 case ')':
  1241.  
  1242.                     /* just decrement brace_ignore if it is positive. If
  1243.                      * brace ignore is not positive at this point then we
  1244.                      * certainly have a syntax error.  Ignore this fact if
  1245.                      * so. */
  1246.                     if (brace_ignore) {
  1247.                         brace_ignore--;
  1248.                     }
  1249.                     break;
  1250.  
  1251.                 case '[':
  1252.  
  1253.                     /* move to end of array bounds */
  1254.                     variable_seen = TRUE;
  1255.                     CToLevelZero(token, token_buffer, infname, outbuf);
  1256.                     break;
  1257.  
  1258.                 default:
  1259.                     CTokenSwap(token);
  1260.                     break;
  1261.             }
  1262.         }
  1263.     }
  1264.  
  1265.     return variable_seen;
  1266. }
  1267.  
  1268.  
  1269. /*----------------------------------------------------------------------------
  1270.  *
  1271.  * COutputCommaDelimitedToken() will output a token and then parse the
  1272.  * statement until ';' or ',' is reached.  The token is output if the passed
  1273.  * token type is requested from the command line.
  1274.  *
  1275.  ---------------------------------------------------------------------------*/
  1276.  
  1277. COutputCommaDelimitedToken(token, token_buffer, token_type, infname, outbuf)
  1278.     Token *token;
  1279.     Buffer *token_buffer;
  1280.     SymbolType token_type;
  1281.     char *infname;
  1282.     char *outbuf;
  1283. {
  1284.     BOOLEAN punctuator_found;
  1285.  
  1286.     /* output the token */
  1287.     COutputToken(token, token_buffer, token_type, infname, outbuf);
  1288.  
  1289.     /* go to the next list punctuator (',' or ';') */
  1290.     punctuator_found = TRUE;
  1291.     while (token->cur_token[0] != ',' &&
  1292.            token->cur_token[0] != ';' &&
  1293.            punctuator_found) {
  1294.         if (strchr(C_open_brace, token->cur_token[0])) {
  1295.             CToLevelZero(token, token_buffer, infname, outbuf);
  1296.         }
  1297.         punctuator_found = CToPunctuator(token, token_buffer,
  1298.                                          infname, outbuf);
  1299.     }
  1300. }
  1301.  
  1302.  
  1303. /*----------------------------------------------------------------------------
  1304.  *
  1305.  * CParseCommaDelimitedList() will parse a token list seperated by commas
  1306.  * until a ';' is found.  The tokens are output if the passed type is
  1307.  * requested from the command line.
  1308.  *
  1309.  ---------------------------------------------------------------------------*/
  1310.  
  1311. CParseCommaDelimitedList(token, token_buffer, token_type, infname, outbuf)
  1312.     Token *token;
  1313.     Buffer *token_buffer;
  1314.     SymbolType token_type;
  1315.     char *infname;
  1316.     char *outbuf;
  1317. {
  1318.     BOOLEAN punctuator_found;
  1319.  
  1320.     /* parse through the list */
  1321.     punctuator_found = TRUE;
  1322.     while (token->cur_token[0] != ';' &&
  1323.            punctuator_found) {
  1324.         punctuator_found = CToPunctuator(token, token_buffer,
  1325.                                          infname, outbuf);
  1326.         if (punctuator_found) {
  1327.             switch (token->cur_token[0]) {
  1328.  
  1329.                 case '(':
  1330.                     /* this is an embedded variable declaration, either a
  1331.                      * complex variable pointer or function pointer, fall
  1332.                      * through after picking out the internal token */
  1333.                     CParseParens(token, token_buffer, infname, outbuf);
  1334.  
  1335.                 case '[':
  1336.                 case ',':
  1337.                 case ';':
  1338.                 case '=':
  1339.  
  1340.                     /* this is one of the proper ending tokens for this type
  1341.                      * of declaration list, so output it and parse to the
  1342.                      * next correct punctuator */
  1343.                     COutputToken(token, token_buffer, token_type,
  1344.                                  infname, outbuf);
  1345.                     while (token->cur_token[0] != ',' &&
  1346.                            token->cur_token[0] != ';' &&
  1347.                            punctuator_found) {
  1348.                         if (strchr(C_open_brace, token->cur_token[0])) {
  1349.                             CToLevelZero(token, token_buffer,
  1350.                                          infname, outbuf);
  1351.                         }
  1352.                         punctuator_found = CToPunctuator(token, token_buffer,
  1353.                                                          infname, outbuf);
  1354.                     }
  1355.                     break;
  1356.                 default:
  1357.                     break;
  1358.             }
  1359.         }
  1360.     }
  1361. }
  1362.  
  1363.  
  1364. /*----------------------------------------------------------------------------
  1365.  *
  1366.  * CParseFunctionOrGlobalVariable() will parse a function, prototype or
  1367.  * global variable syntax.
  1368.  *
  1369.  ---------------------------------------------------------------------------*/
  1370.  
  1371. CParseFunctionOrGlobalVariable(token, token_buffer, infname, outbuf)
  1372.     Token *token;
  1373.     Buffer *token_buffer;
  1374.     char *infname;
  1375.     char *outbuf;
  1376. {
  1377.     char *line_buf;             /* the first token buffer */
  1378.     int charloc;                /* the char location of sbuf1 */
  1379.     int tokenline;              /* the line number of sbuf1 */
  1380.  
  1381.     BOOLEAN token_found;
  1382.     BOOLEAN punctuator_found;
  1383.     BOOLEAN last_token_known;
  1384.     BOOLEAN variable_seen;
  1385.  
  1386.     /* init */
  1387.     charloc = 0;
  1388.     tokenline = 1;
  1389.     line_buf = malloc(MAX_TOKEN_LENGTH);
  1390.     line_buf[0] = '\0';
  1391.  
  1392.     /* save the previous token */
  1393.     last_token_known = CIsDeclarationToken(token->prev_token);
  1394.     if (!last_token_known) {
  1395.  
  1396.         /* If this is not a known token then it may be a function name. Save
  1397.          * it then look further at the syntax.  This also may be a symbol
  1398.          * previously defined via a typedef which alters the syntax of C/C++ */
  1399.         strcpy(line_buf, token->prev_token);
  1400.         charloc = *(token->prev_char_location);
  1401.         tokenline = *(token->prev_token_line);
  1402.     }
  1403.  
  1404.     /* This is a function or prototype or global variable go to brace_ignore
  1405.      * level zero again. */
  1406.     variable_seen = CParseParens(token, token_buffer, infname, outbuf);
  1407.  
  1408.     /* Check to see if this is a function, prototype, or global variable. If
  1409.      * the token is a ';' and last_token_known is false then we assume a
  1410.      * function.  Strange variable declarations may fool this, but not
  1411.      * likely. If the character is a '(' then it is certainly a function or
  1412.      * prototype unless variable_seen is TRUE, then it is a variable. If the
  1413.      * character is a '[', ',' then it is certainly a variable declaration.
  1414.      * If the character is a ';' and last_token_known is true then it is a
  1415.      * variable declaration.  If the token is anything else then it is a
  1416.      * function. */
  1417.     token_found = CNextToken(token, token_buffer, infname, outbuf);
  1418.     if (token_found) {
  1419.         switch (token->cur_token[0]) {
  1420.  
  1421.             case ';':
  1422.  
  1423.                 /* determine if a prototype or a variable declaration. if the
  1424.                  * last_token_known is true then it is a global variable.  If
  1425.                  * the token was a symbol defined by a typedef then this
  1426.                  * distinction is incorrect since typedef actually alters
  1427.                  * syntax.  This is correct for the large majority of cases
  1428.                  * since most do not enclose simple variable declarations in
  1429.                  * parens. */
  1430.                 if (last_token_known) {
  1431.  
  1432.                     /* this is a global variable */
  1433.                     COutputToken(token, token_buffer, GlobalVariable,
  1434.                                  infname, outbuf);
  1435.                 }
  1436.                 else {
  1437.  
  1438.                     /* this is a prototype, copy saved token back to
  1439.                      * prev_token, output and continue */
  1440.                     strcpy(token->prev_token, line_buf);
  1441.                     *(token->prev_char_location) = charloc;
  1442.                     *(token->prev_token_line) = tokenline;
  1443.                     COutputToken(token, token_buffer, ProtoType,
  1444.                                  infname, outbuf);
  1445.                 }
  1446.                 break;
  1447.  
  1448.             case '(':
  1449.  
  1450.                 if (variable_seen) {
  1451.  
  1452.                     /* this is a variable declaration */
  1453.                     COutputCommaDelimitedToken(token, token_buffer,
  1454.                                                GlobalVariable,
  1455.                                                infname, outbuf);
  1456.                     CParseCommaDelimitedList(token, token_buffer,
  1457.                                              GlobalVariable,
  1458.                                              infname, outbuf);
  1459.                 }
  1460.                 else {
  1461.  
  1462.                     /* move to level zero again */
  1463.                     CToLevelZero(token, token_buffer, infname, outbuf);
  1464.  
  1465.                     /* obtain the next token */
  1466.                     token_found = CNextToken(token, token_buffer,
  1467.                                              infname, outbuf);
  1468.  
  1469.                     if (token_found) {
  1470.  
  1471.                         /* check if prototype, function or function pointer
  1472.                          * variable declaration */
  1473.                         switch (token->cur_token[0]) {
  1474.  
  1475.                             case '=':
  1476.  
  1477.                                 /* this is a function pointer variable
  1478.                                  * declaration */
  1479.                                 COutputCommaDelimitedToken(token,
  1480.                                                            token_buffer,
  1481.                                                            GlobalVariable,
  1482.                                                            infname, outbuf);
  1483.                                 CParseCommaDelimitedList(token, token_buffer,
  1484.                                                          GlobalVariable,
  1485.                                                          infname, outbuf);
  1486.                                 break;
  1487.  
  1488.                             case ';':
  1489.  
  1490.                                 /* this is a prototype, output it */
  1491.                                 COutputToken(token, token_buffer,
  1492.                                              ProtoType, infname, outbuf);
  1493.                                 break;
  1494.  
  1495.                             default:
  1496.  
  1497.                                 /* this is a function */
  1498.                                 COutputToken(token, token_buffer,
  1499.                                              Function, infname, outbuf);
  1500.  
  1501.                                 /* parse through function */
  1502.                                 punctuator_found = TRUE;
  1503.                                 while (token->cur_token[0] != '{' &&
  1504.                                        punctuator_found) {
  1505.                                     punctuator_found =
  1506.                                         CToPunctuator(token, token_buffer,
  1507.                                                       infname, outbuf);
  1508.                                 }
  1509.                                 if (punctuator_found) {
  1510.                                     CToLevelZero(token, token_buffer,
  1511.                                                  infname, outbuf);
  1512.                                 }
  1513.                                 break;
  1514.                         }
  1515.                     }
  1516.                 }
  1517.                 break;
  1518.  
  1519.             case '[':
  1520.             case '=':
  1521.             case ',':
  1522.  
  1523.                 /* global variables */
  1524.                 COutputCommaDelimitedToken(token, token_buffer,
  1525.                                            GlobalVariable,
  1526.                                            infname, outbuf);
  1527.                 CParseCommaDelimitedList(token, token_buffer,
  1528.                                          GlobalVariable,
  1529.                                          infname, outbuf);
  1530.                 break;
  1531.  
  1532.             default:
  1533.  
  1534.                 /* this is a function, copy saved token back to prev_token,
  1535.                  * output and continue */
  1536.                 strcpy(token->prev_token, line_buf);
  1537.                 *(token->prev_char_location) = charloc;
  1538.                 *(token->prev_token_line) = tokenline;
  1539.                 COutputToken(token, token_buffer,
  1540.                              Function, infname, outbuf);
  1541.  
  1542.                 /* parse through function */
  1543.                 punctuator_found = TRUE;
  1544.                 while (token->cur_token[0] != '{' &&
  1545.                        punctuator_found) {
  1546.                     punctuator_found =
  1547.                         CToPunctuator(token, token_buffer, infname, outbuf);
  1548.                 }
  1549.                 if (punctuator_found) {
  1550.                     CToLevelZero(token, token_buffer, infname, outbuf);
  1551.                 }
  1552.                 break;
  1553.         }
  1554.     }
  1555.     free(line_buf);
  1556. }
  1557.  
  1558.  
  1559. /*----------------------------------------------------------------------------
  1560.  *
  1561.  * CParseNOP() will parse an as of yet unrecognized statement.  If I run into
  1562.  * a punctuator at this time then I have found either a structure declaration
  1563.  * (C++ 2.0), or a global variable declaration.  If the punctuator is '[',
  1564.  * ',', '=', or ';' then it is a global variable declaration.  If the
  1565.  * punctuator is a '{' then we have a structure declaration at this time we
  1566.  * should not run into any closing punctuators or syntax is in a bad way
  1567.  *
  1568.  ---------------------------------------------------------------------------*/
  1569.  
  1570. CParseNOP(token, token_buffer, infname, outbuf)
  1571.     Token *token;
  1572.     Buffer *token_buffer;
  1573.     char *infname;
  1574.     char *outbuf;
  1575. {
  1576.     BOOLEAN token_found;
  1577.  
  1578.     switch (token->cur_token[0]) {
  1579.         case ';':
  1580.         case '=':
  1581.         case ',':
  1582.         case '[':
  1583.  
  1584.             /* global variables are here */
  1585.             COutputCommaDelimitedToken(token, token_buffer,
  1586.                                        GlobalVariable,
  1587.                                        infname, outbuf);
  1588.             CParseCommaDelimitedList(token, token_buffer,
  1589.                                      GlobalVariable,
  1590.                                      infname, outbuf);
  1591.             token->extern_active = FALSE;
  1592.             token->static_active = FALSE;
  1593.             break;
  1594.  
  1595.         case '{':
  1596.  
  1597.             /* this is a structure (C++ syntax) */
  1598.             /* output it */
  1599.             COutputToken(token, token_buffer, Structure, infname, outbuf);
  1600.  
  1601.             /* move through declaration */
  1602.             CToLevelZero(token, token_buffer, infname, outbuf);
  1603.  
  1604.             /* get the next token */
  1605.             token_found = CNextToken(token, token_buffer, infname, outbuf);
  1606.  
  1607.             /* if a token is available then output the list */
  1608.             if (token_found) {
  1609.                 CParseCommaDelimitedList(token, token_buffer,
  1610.                                          GlobalVariable,
  1611.                                          infname, outbuf);
  1612.             }
  1613.             token->extern_active = FALSE;
  1614.             token->static_active = FALSE;
  1615.             break;
  1616.  
  1617.         case '(':
  1618.  
  1619.             CParseFunctionOrGlobalVariable(token, token_buffer,
  1620.                                            infname, outbuf);
  1621.             token->extern_active = FALSE;
  1622.             token->static_active = FALSE;
  1623.             break;
  1624.  
  1625.         default:
  1626.  
  1627.             /* true NOP */
  1628.             break;
  1629.     }
  1630. }
  1631.  
  1632.  
  1633. /*----------------------------------------------------------------------------
  1634.  *
  1635.  * CParseEnumerationConstants() will parse constants within an enumeration
  1636.  * declaration
  1637.  *
  1638.  ---------------------------------------------------------------------------*/
  1639.  
  1640. CParseEnumerationConstants(token, token_buffer, infname, outbuf)
  1641.     Token *token; 
  1642.     Buffer *token_buffer;
  1643.     char *infname;
  1644.     char *outbuf;
  1645. {
  1646.     BOOLEAN punctuator_found;
  1647.  
  1648.     char *open_brace = "({[";
  1649.  
  1650.     /* obtain the enumeration constants */
  1651.     punctuator_found = TRUE;
  1652.  
  1653.     while (token->cur_token[0] != '}' &&
  1654.            punctuator_found) {
  1655.         punctuator_found = CToPunctuator(token, token_buffer, 
  1656.                                          infname, outbuf);
  1657.         if (punctuator_found) {
  1658.             switch (token->cur_token[0]) {
  1659.  
  1660.                 case ',':
  1661.                 case '=':
  1662.  
  1663.                     /* this is one of the proper ending tokens for this type
  1664.                      * of declaration list, so output it and parse to the
  1665.                      * next correct punctuator */
  1666.                     COutputToken(token, token_buffer, EnumerationConstant,
  1667.                                  infname, outbuf);
  1668.                     while (token->cur_token[0] != ',' &&
  1669.                            token->cur_token[0] != '}' &&
  1670.                            punctuator_found) {
  1671.                         if (strchr(open_brace, token->cur_token[0])) {
  1672.                             CToLevelZero(token, token_buffer,
  1673.                                          infname, outbuf);
  1674.                         }
  1675.                         punctuator_found = CToPunctuator(token, token_buffer,
  1676.                                                          infname, outbuf);
  1677.                     }
  1678.                     break;
  1679.  
  1680.                 default:
  1681.                     break;
  1682.             }
  1683.         }
  1684.     }
  1685. }
  1686.  
  1687.  
  1688. /*----------------------------------------------------------------------------
  1689.  *
  1690.  * CParseDeclarationStatement() will parse struct, enum and union
  1691.  * declarations.  take the token just before the first punctuator, run
  1692.  * through the top level braces and parse for variables if the first
  1693.  * punctuator is a ';' then this is a global variable declaration, if the
  1694.  * first token[0] is a '{' then this is a global variable declaration.
  1695.  *
  1696.  ---------------------------------------------------------------------------*/
  1697.  
  1698. CParseDeclarationStatement(token, token_buffer, type, infname, outbuf)
  1699.     Token *token;
  1700.     Buffer *token_buffer;
  1701.     SymbolType type;
  1702.     char *infname;
  1703.     char *outbuf;
  1704. {
  1705.     BOOLEAN token_found;
  1706.     BOOLEAN punctuator_found;
  1707.     BOOLEAN primary_parse;
  1708.  
  1709.     punctuator_found = CToPunctuator(token, token_buffer, infname, outbuf);
  1710.     if (punctuator_found) {
  1711.  
  1712.         /* init */
  1713.         primary_parse = TRUE;
  1714.  
  1715.         /* switch on current token */
  1716.         switch (token->cur_token[0]) {
  1717.  
  1718.                 /* this is truly an object declaration */
  1719.             case '{':
  1720.  
  1721.                 /* output only if this is not a variable declaration */
  1722.                 if (token->token_count != 1) {
  1723.  
  1724.                     /* output it */
  1725.                     COutputToken(token, token_buffer, type, infname, outbuf);
  1726.                 }
  1727.  
  1728.                 /* check if enumeration */
  1729.                 if (token->token_count != 1 &&
  1730.                     type == Enumeration) {
  1731.  
  1732.                     /* obtain the enumeration constants */
  1733.                     CParseEnumerationConstants(token, token_buffer,
  1734.                                                infname, outbuf);
  1735.                 }
  1736.                 else {
  1737.  
  1738.                     /* move through declaration and fall through */
  1739.                     CToLevelZero(token, token_buffer, infname, outbuf);
  1740.                 }
  1741.  
  1742.                 /* get the next token, if one not available then break out of
  1743.                  * case */
  1744.                 token_found = CNextToken(token, token_buffer,
  1745.                                          infname, outbuf);
  1746.                 if (!token_found)
  1747.                     break;
  1748.  
  1749.                 /* fall through to take care of variable declarations after
  1750.                  * setting pre-parse flag */
  1751.                 primary_parse = FALSE;
  1752.  
  1753.             case ';':
  1754.             case '=':
  1755.             case ',':
  1756.             case '[':
  1757.  
  1758.                 /* if this is the first seen then output it */
  1759.                 if (primary_parse) {
  1760.                     COutputCommaDelimitedToken(token, token_buffer,
  1761.                                                GlobalVariable,
  1762.                                                infname, outbuf);
  1763.                 }
  1764.  
  1765.                 CParseCommaDelimitedList(token, token_buffer,
  1766.                                          GlobalVariable,
  1767.                                          infname, outbuf);
  1768.                 break;
  1769.  
  1770.             case '(':
  1771.  
  1772.                 CParseFunctionOrGlobalVariable(token, token_buffer,
  1773.                                                infname, outbuf);
  1774.                 break;
  1775.  
  1776.             default:
  1777.  
  1778.                 /* not reached */
  1779.                 break;
  1780.         }
  1781.     }
  1782. }
  1783.  
  1784.  
  1785. /*----------------------------------------------------------------------------
  1786.  *
  1787.  * CParseTypeDefinition() parses the typedef statement.  take the token just
  1788.  * before the first *correct* punctuator, the ';', ',' or the '['.  Tag any
  1789.  * declarations being done here, get the next token
  1790.  *
  1791.  ---------------------------------------------------------------------------*/
  1792.  
  1793. CParseTypeDefinition(token, token_buffer, infname, outbuf)
  1794.     Token *token;
  1795.     Buffer *token_buffer;
  1796.     char *infname;
  1797.     char *outbuf;
  1798. {
  1799.     BOOLEAN token_found;
  1800.     BOOLEAN parens_found;
  1801.     BOOLEAN special_found;
  1802.     BOOLEAN punctuator_found;
  1803.  
  1804.     int token_count;
  1805.     SymbolType tmptype;
  1806.  
  1807.     token_found = CNextToken(token, token_buffer, infname, outbuf);
  1808.  
  1809.     if (token_found) {
  1810.  
  1811.         /* check the type of the token for future use */
  1812.         tmptype = CTokenType(token->cur_token);
  1813.  
  1814.         /* parse the typedef */
  1815.         parens_found = FALSE;
  1816.         special_found = FALSE;
  1817.         token_count = 0;
  1818.         while (token->cur_token[0] != ';' &&
  1819.                token->cur_token[0] != ',' &&
  1820.                token->cur_token[0] != '[' &&
  1821.                token_found &&
  1822.                !special_found) {
  1823.  
  1824.             /* parse for defines */
  1825.             if (token_found) {
  1826.  
  1827.                 /* handle the punctuator */
  1828.                 switch (token->cur_token[0]) {
  1829.  
  1830.                     case '{':
  1831.  
  1832.                         /* pass through any defines going on here */
  1833.                         if (token->cur_token[0] == '{') {
  1834.  
  1835.                             /* if the token count is > 1 here then we have a
  1836.                              * named declaration and need to output the
  1837.                              * token, output only if the token type is enum,
  1838.                              * struct, or union */
  1839.                             if (token_count > 1 &&
  1840.                                 (tmptype == Structure ||
  1841.                                  tmptype == Enumeration ||
  1842.                                  tmptype == Union)) {
  1843.                                 COutputToken(token, token_buffer,
  1844.                                              tmptype, infname, outbuf);
  1845.                             }
  1846.  
  1847.                             /* check if enumeration */
  1848.                             if (tmptype == Enumeration) {
  1849.  
  1850.                                 /* obtain the enumeration constants */
  1851.                                 CParseEnumerationConstants(token,
  1852.                                                            token_buffer,
  1853.                                                            infname, outbuf);
  1854.                             }
  1855.                             else {
  1856.  
  1857.                                 /* go back to level 0 */
  1858.                                 CToLevelZero(token, token_buffer,
  1859.                                              infname, outbuf);
  1860.                             }
  1861.                         }
  1862.                         break;
  1863.  
  1864.                     case '(':
  1865.  
  1866.                         /* if this is the top level and we have already been
  1867.                          * through a set of parens then we know this to be a
  1868.                          * function typedef so we ouput the previous token,
  1869.                          * otherwise check the previous token and if it is a
  1870.                          * known keyword then just eat the token and continue */
  1871.                         if (parens_found) {
  1872.                             COutputToken(token, token_buffer,
  1873.                                          TypeDefinition, infname, outbuf);
  1874.                             CToLevelZero(token, token_buffer,
  1875.                                          infname, outbuf);
  1876.                             special_found = TRUE;
  1877.                         }
  1878.                         else {
  1879.  
  1880.                             /* Move back to the top level */
  1881.                             CParseParens(token, token_buffer,
  1882.                                          infname, outbuf);
  1883.  
  1884.                             /* next paren we find we know we have a token */
  1885.                             parens_found = TRUE;
  1886.  
  1887.                             /* swap to prevent loss of token */
  1888.                             CTokenSwap(token);
  1889.                         }
  1890.                         break;
  1891.  
  1892.                     default:
  1893.  
  1894.                         /* if we have another token after a paren parse then
  1895.                          * we know the token in the parens was nothing
  1896.                          * special */
  1897.                         parens_found = FALSE;
  1898.                         break;
  1899.                 }
  1900.             }
  1901.  
  1902.             /* get another token */
  1903.             CTokenSwap(token);
  1904.             token_found = CNextToken(token, token_buffer, infname, outbuf);
  1905.             token_count++;
  1906.         }
  1907.  
  1908.         /* output the typedef names if appropriate */
  1909.         if (token->prev_token[0] != '}' &&
  1910.             token_found) {
  1911.  
  1912.             /* don't output the first token if already done */
  1913.             if (!special_found) {
  1914.                 COutputCommaDelimitedToken(token, token_buffer,
  1915.                                            TypeDefinition,
  1916.                                            infname, outbuf);
  1917.             }
  1918.  
  1919.             /* parse through the rest of the typedef names */
  1920.             CParseCommaDelimitedList(token, token_buffer,
  1921.                                      TypeDefinition,
  1922.                                      infname, outbuf);
  1923.         }
  1924.     }
  1925. }
  1926.  
  1927.  
  1928. /*----------------------------------------------------------------------------
  1929.  *
  1930.  * CParseClass() will parse the C++ class syntax.  take the token just before
  1931.  * the first '{', ',' or ':' and run through the top level braces if there
  1932.  *
  1933.  ---------------------------------------------------------------------------*/
  1934.  
  1935. CParseClass(token, token_buffer, infname, outbuf)
  1936.     Token *token;
  1937.     Buffer *token_buffer;
  1938.     char *infname;
  1939.     char *outbuf;
  1940. {
  1941.     BOOLEAN token_found;
  1942.  
  1943.     token_found = TRUE;
  1944.     while (token->cur_token[0] != '{' &&
  1945.            token->cur_token[0] != ':' &&
  1946.            token->cur_token[0] != ';' &&
  1947.            token_found) {
  1948.  
  1949.         /* save the current token */
  1950.         CTokenSwap(token);
  1951.  
  1952.         /* get the next token */
  1953.         token_found = CNextToken(token, token_buffer, infname, outbuf);
  1954.     }
  1955.  
  1956.     /* output the class name */
  1957.     if (token_found) {
  1958.         COutputToken(token, token_buffer, Class, infname, outbuf);
  1959.  
  1960.         /* parse through the remainder of the statement */
  1961.         while (token->cur_token[0] != ';' &&
  1962.                token_found) {
  1963.             if (token->cur_token[0] == '{') {
  1964.  
  1965.                 /* move back to the zero level */
  1966.                 CToLevelZero(token, token_buffer, infname, outbuf);
  1967.             }
  1968.  
  1969.             token_found = CNextToken(token, token_buffer, infname, outbuf);
  1970.         }
  1971.     }
  1972. }
  1973.  
  1974.  
  1975. /*----------------------------------------------------------------------------
  1976.  *
  1977.  * CTags() tags an input stream assuming standard ANSI 2.0 C/C++ syntax.
  1978.  * Long tokens are allowed, ANSI requires only 31 significant, note that if
  1979.  * token length exceeds MAX_TOKEN_LENGTH this parser will die a horrible
  1980.  * death (or at the very least do ugly things to someone else's memory),
  1981.  * with the large size of MAX_TOKEN_LENGTH, anyone caught on this hook
  1982.  * deserves what they get...
  1983.  *
  1984.  ---------------------------------------------------------------------------*/
  1985.  
  1986. CTags(inbuf, infname, outbuf)
  1987.     char *inbuf;
  1988.     char *infname;
  1989.     char *outbuf;
  1990. {
  1991.     SymbolType type;            /* the type of the current token */
  1992.  
  1993.     Token *token;               /* current state variable */
  1994.     Buffer *token_buffer;       /* input buffer */
  1995.  
  1996.     BOOLEAN token_found;        /* set by CNextToken() */
  1997.  
  1998.     /* allocate the Buffer and Token memory */
  1999.     token = (Token *) malloc(sizeof(Token));
  2000.     token_buffer = (Buffer *) malloc(sizeof(Token));
  2001.  
  2002.     /* init the parser engine */
  2003.     point = 0;
  2004.     CParserInit();
  2005.     token->token_count = 0;
  2006.  
  2007.     /* init the current token buffers */
  2008.     token->cur_token = token->sbuf1;
  2009.     token->cur_char_location = &(token->charloc1);
  2010.     token->cur_token_line = &(token->tokenline1);
  2011.     token->cur_token[0] = '\0';
  2012.     *(token->cur_char_location) = 0;
  2013.     *(token->cur_token_line) = 1;
  2014.  
  2015.     /* init the previous token buffers */
  2016.     token->prev_token = token->sbuf2;
  2017.     token->prev_char_location = &(token->charloc2);
  2018.     token->prev_token_line = &(token->tokenline2);
  2019.     token->prev_token[0] = '\0';
  2020.     *(token->prev_char_location) = 0;
  2021.     *(token->prev_token_line) = 1;
  2022.  
  2023.     /* init the input buffers */
  2024.     token_buffer->token_line_location = 1;
  2025.     token_buffer->inbuf = inbuf;
  2026.  
  2027.     /* init Extern and Static state */
  2028.     token->extern_active = FALSE;
  2029.     token->static_active = FALSE;
  2030.  
  2031.     /* get the first token */
  2032.     token_found = CNextToken(token, token_buffer, infname, outbuf);
  2033.  
  2034.     /* loop through the file */
  2035.     while (token_found) {
  2036.  
  2037.         /* obtain the token type */
  2038.         type = CTokenType(token->cur_token);
  2039.  
  2040.         /* react on the token type */
  2041.         switch (type) {
  2042.  
  2043.             case NOP:
  2044.                 CParseNOP(token, token_buffer, infname, outbuf);
  2045.                 break;
  2046.  
  2047.             case Structure:
  2048.             case Enumeration:
  2049.             case Union:
  2050.                 CParseDeclarationStatement(token, token_buffer,
  2051.                                            type, infname, outbuf);
  2052.                 break;
  2053.  
  2054.             case TypeDefinition:
  2055.                 CParseTypeDefinition(token, token_buffer, infname, outbuf);
  2056.                 break;
  2057.  
  2058.             case Class:
  2059.                 CParseClass(token, token_buffer, infname, outbuf);
  2060.                 break;
  2061.  
  2062.             case Extern:
  2063.                 token->extern_active = TRUE;
  2064.                 break;
  2065.  
  2066.             case Static:
  2067.                 token->static_active = TRUE;
  2068.                 break;
  2069.  
  2070.             default:
  2071.                 /* not reached */
  2072.                 break;
  2073.         }
  2074.  
  2075.         if (type != Extern &&
  2076.             type != Static &&
  2077.             type != NOP) {
  2078.  
  2079.             /* turn off the extern flag */
  2080.             token->extern_active = FALSE;
  2081.             token->static_active = FALSE;
  2082.         }
  2083.  
  2084.         /* swap state variables and get the next token */
  2085.         CTokenSwap(token);
  2086.         token_found = CNextToken(token, token_buffer, infname, outbuf);
  2087.     }
  2088.  
  2089.     free(token);
  2090.     free(token_buffer);
  2091. }
  2092.  
  2093.  
  2094. /*----------------------------------------------------------------------------
  2095.  *
  2096.  * tag_suffix_c(), tag_suffix_h() and tag_suffix_e() are recognized procedure
  2097.  * names to the tags package in Epsilon and will be called automatically when
  2098.  * tagging needs to happen for these extensions.  These are replacement names
  2099.  * for the routines of the same name defined in tags.e.
  2100.  *
  2101.  ---------------------------------------------------------------------------*/
  2102.  
  2103. tag_suffix_c()
  2104. {
  2105.     /* the third parameter, the output buffer name is not actually used by
  2106.      * anyone but is left here for a time when this information may be
  2107.      * needed.  The current algorithm is to let the funtion add_tag() decide
  2108.      * the buffer name to send the output to.  As a little more than
  2109.      * coincedence, the name used here is the same used in add_tag() defined
  2110.      * in tags.e */
  2111.     CTags(bufname, filename, "-tags");
  2112. }
  2113.  
  2114. tag_suffix_h()
  2115. {
  2116.     tag_suffix_c();
  2117. }
  2118.  
  2119. tag_suffix_e()
  2120. {
  2121.     tag_suffix_c();
  2122. }
  2123.  
  2124. tag_suffix_cc()
  2125. {
  2126.     tag_suffix_c();
  2127. }
  2128.  
  2129. tag_suffix_cpp()
  2130. {
  2131.     tag_suffix_c();
  2132. }
  2133.  
  2134. /* rebuild the default character maps */
  2135. when_loading()
  2136. {
  2137. #define UCLC(up, low)   def_char_class[low] = C_LOWER, \
  2138.                         def_char_class[up] = C_UPPER, \
  2139.                         def_srch_case_map[up] = low, \
  2140.                         def_case_map[low] = up, \
  2141.                         def_case_map[up] = low
  2142.  
  2143.     int i, j;
  2144.  
  2145.     for (i = 0; i < 256; i++)
  2146.         def_case_map[i] = def_srch_case_map[i] = i;
  2147.     for (i = 'A', j = 'a'; i <= 'Z'; i++, j++)
  2148.         UCLC(i, j);
  2149.     for (i = 131; i < 154; i++)
  2150.         def_char_class[i] = C_LOWER;
  2151.     for (i = 160; i < 164; i++)
  2152.         def_char_class[i] = C_LOWER;
  2153.     UCLC('Ç', 'ç');
  2154.     UCLC('Ä', 'ä');
  2155.     UCLC('Å', 'å');
  2156.     UCLC('É', 'é');
  2157.     UCLC('Æ', 'æ');
  2158.     UCLC('Ö', 'ö');
  2159.     UCLC('Ü', 'ü');
  2160.     UCLC('Ñ', 'ñ');
  2161. }
  2162.